package com.iflytek.sbd.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONPObject;
import com.iflytek.sbd.utils.ParameterUtils;
import com.iflytek.sbd.utils.RedisUtils;
import com.iflytek.sbd.vo.InfoVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisStringCommands;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.types.Expiration;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @program: sbd
 * @description:专门用来测试接口重复调用如何解决
 * @author: 陈亮
 * @create: 2022-01-15 11:46
 */
@Api(tags = "切面测试demo--废弃")
@RestController
@RequestMapping("/redis")
public class RedisBiz {


    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private RedisUtils redisUtils;


    @PostMapping(value = "/get")
    public InfoVO getInfo(InfoVO vo) {

        String md5 = ParameterUtils.paramMD5(JSON.toJSONString(vo), "requestTime");
        Boolean result = redisUtils.limitMethodRepeatedConsumption(md5, "chenliang", "methedName", 20000);
        if (result) {
            return new InfoVO();
        } else {
            return vo;
        }
    }

}
